/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.offlanguagezhcn.controller
 * FILE    NAME: OffLanguageZhCnDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.controller;

import java.io.IOException;
import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.jodinfo.outmirror.entity.OffLanguageZhCnEntity;
import com.jodinfo.outmirror.service.OffLanguageZhCnBizService;
import com.jodinfo.outmirror.util.PicFileUpload;
import com.jodinfo.outmirror.util.ResponseEntity;
import com.jodinfo.outmirror.util.StringUtils;
import com.jodinfo.outmirror.util.SysConstant;




@Controller
@RequestMapping(value = "/OffLanguageZhCnAdmin")
public class OffLanguageZhCnController  {
	
@Resource(name="offLanguageZhCnBizService")
private OffLanguageZhCnBizService offLanguageZhCnBizService;
/**
*  list数据源
* 
* */
@RequestMapping(value = "/List")
@ResponseBody
public String OffLanguageZhCnList(OffLanguageZhCnEntity offLanguageZhCnEntity) {
	if(offLanguageZhCnEntity==null){
		offLanguageZhCnEntity = new OffLanguageZhCnEntity();
		offLanguageZhCnEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		offLanguageZhCnEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	if (offLanguageZhCnEntity.getPageSize() == null) {
		offLanguageZhCnEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	offLanguageZhCnEntity.setIsDel(SysConstant.IS_DEL_N);
	//offLanguageZhCnEntity.setCurrentUser(UserContext.getUser());
	String str = offLanguageZhCnBizService.queryListForPageOffLanguageZhCn(offLanguageZhCnEntity);
	return str;
}
/**
* OffLanguageZhCnEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView offLanguageZhCnListPage(OffLanguageZhCnEntity offLanguageZhCnEntity,HttpServletRequest request,Model model) {
	model.addAttribute("parentId",offLanguageZhCnEntity.getParentId());
	ServletContext servletContext=request.getSession().getServletContext();
	model.addAttribute("cdnAddress", servletContext.getInitParameter("cdnAddress"));
	String projectName = request.getContextPath();
	model.addAttribute("projectName",projectName);
	return new ModelAndView(returnPath("offLanguageZhCnList"));
}


/**
* OffMenuEntity List页面
* 
* */
@RequestMapping(value = "/queryAll")
public @ResponseBody String offLanguageZhCnQueryAll(OffLanguageZhCnEntity offLanguageZhCnEntity) {
	offLanguageZhCnEntity.setIsDel(SysConstant.IS_DEL_N);
	return offLanguageZhCnBizService.queryAllOffLanguageZhCn(offLanguageZhCnEntity);
}

/**
* OffLanguageZhCnEntity详细页 
* 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView offLanguageZhCnEditPage(OffLanguageZhCnEntity offLanguageZhCnEntity,HttpServletRequest request,Model model) {
	ServletContext servletContext=request.getSession().getServletContext();
	model.addAttribute("cdnAddress", servletContext.getInitParameter("cdnAddress"));
	String projectName = request.getContextPath();
	model.addAttribute("projectName",projectName);
	return new ModelAndView(returnPath("offLanguageZhCnAdd"));
}
/**
 * 查询OffLanguageZhCnEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findOffLanguageZhCnData(HttpServletRequest request) {
	String id = request.getParameter("id");
	OffLanguageZhCnEntity offLanguageZhCnEntity =  offLanguageZhCnBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(offLanguageZhCnEntity); 
}

/**
 * 保存或更新OffLanguageZhCn 
 * @throws IOException 
 * 
 * */
@RequestMapping(value = "/saveOffLanguageZhCn",produces = "application/json;charset=UTF-8")
public @ResponseBody String saveOffLanguageZhCnData(HttpServletRequest request,MultipartFile picture) throws IOException {
	ResponseEntity rs = null;
	OffLanguageZhCnEntity offLanguageZhCnEntity = new OffLanguageZhCnEntity();
	offLanguageZhCnEntity.setId(new BigInteger(request.getParameter("id")));
	offLanguageZhCnEntity.setTextId(request.getParameter("textId"));
	offLanguageZhCnEntity.setMenuId(request.getParameter("menuId"));
	offLanguageZhCnEntity.setTitle(request.getParameter("title"));
	offLanguageZhCnEntity.setContent(request.getParameter("content"));
	offLanguageZhCnEntity.setContentD(request.getParameter("contentD"));
	if (picture != null && StringUtils.isNotEmpty(picture.getOriginalFilename())) {
		//String buffStr = StringUtils.getBytes(picture);
		offLanguageZhCnEntity.setPicture(picture.getOriginalFilename());
		//offLanguageZhCnEntity.setPictureStream(buffStr);
		String newfilePath = PicFileUpload.uploadFile(picture, request,request.getParameter("textId"));  
		offLanguageZhCnEntity.setPictureUrl(newfilePath);
	}
	if(offLanguageZhCnEntity.getId()!=null){
		rs = offLanguageZhCnBizService.updateOffLanguageZhCn(offLanguageZhCnEntity);
	}else{
		rs = offLanguageZhCnBizService.addOffLanguageZhCn(offLanguageZhCnEntity);
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出OffLanguageZhCnEntity
 * @author ZhangYuanYuan
 * @date 2015-7-09  下午2:13:28
 * @return
 */
@RequestMapping(value = "/exportOffLanguageZhCnExcel")
public void exportOffLanguageZhCnExcel(OffLanguageZhCnEntity offLanguageZhCnEntity,HttpServletResponse response) {
		//offLanguageZhCnBizService.exportOffLanguageZhCn(offLanguageZhCnEntity, response);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
